//
//  SYHomeViewController.m
//  BShouGongKe
//
//  Created by 曹雁彬 on 15/8/10.
//  Copyright (c) 2015年 L750. All rights reserved.
//

#import "SYHomeViewController.h"
#import "Header.h"
@interface SYHomeViewController ()<UIScrollViewDelegate>
@property(nonatomic,strong)UIScrollView *scorllButonView;
@property(nonatomic,strong)UIScrollView *homeScorllView;
@property(nonatomic,strong)UIView *scrollLine;
@end

@implementation SYHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
   self.navigationController.navigationBar.translucent = NO;
    self.automaticallyAdjustsScrollViewInsets = NO;
   // self.navigationController.navigationBarHidden = YES;
    self.navigationItem.title = @"首 页";
    [self createScorllButton];
      // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
  
    // Do any additional setup after loading the view.
}
- (void)createScorllButton
{
    _scorllButonView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
    //_scorllButonView.backgroundColor = [UIColor redColor];
    _scorllButonView.contentSize = CGSizeMake((SCREEN_WIDTH/4)*9, 0);
    _scorllButonView.contentOffset = CGPointMake(0, 0);
    _scorllButonView.bounces = NO;
    _scorllButonView.showsHorizontalScrollIndicator = NO;
    //_scorllButonView.contentOffset = CGPointMake(SCREEN_WIDTH*4, 0);
    
    
    
    _scrollLine = [[UIView alloc]initWithFrame:CGRectMake(0, 40, SCREEN_WIDTH/4, 2)];
    _scrollLine.backgroundColor = [UIColor blackColor];
    [self.view addSubview:_scrollLine];
    NSArray *array = @[@"首  页",@"创意手工",@"旧物改造",@"手工皮具",@"电子科技",@"美食园艺",@"手工布艺",@"粘土/陶艺",@"更多分类"];
    CGFloat x = 0;
    for (NSString *str in array) {
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        //button.backgroundColor = [UIColor cyanColor];
        [button setTitle:str forState:UIControlStateNormal];
        button.frame = CGRectMake(x, 0, SCREEN_WIDTH/4, 40);
        [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        x += SCREEN_WIDTH/4;
        [_scorllButonView addSubview:button];
    }
    
    [self.view addSubview:_scorllButonView];
    [self HomeScorllView];

}
- (void)HomeScorllView
{
    _homeScorllView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 42, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _homeScorllView.backgroundColor = [UIColor redColor];
    _homeScorllView.contentSize = CGSizeMake(SCREEN_WIDTH*9, 0);
    _homeScorllView.contentOffset = CGPointMake(0, 0);
    _homeScorllView.bounces = NO;
    _homeScorllView.showsVerticalScrollIndicator = NO;
    _homeScorllView.pagingEnabled = YES;
    _homeScorllView.delegate = self;
    [self.view addSubview:_homeScorllView];
}
- (void)changeFame:(CGFloat)x
{
      if (x<4) {
        [UIView animateWithDuration:0.2 animations:^{
            _scrollLine.frame = CGRectMake(x*SCREEN_WIDTH/4, 40, SCREEN_WIDTH/4, 2);
        }];
    }
    if (x>3) {
        
        [UIView animateWithDuration:0.2 animations:^{
            _scorllButonView.contentOffset = CGPointMake((SCREEN_WIDTH/4)*(x-3), 0);
        }];
    }

}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    CGFloat x = scrollView.contentOffset.x/SCREEN_WIDTH;
    [self changeFame:x];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
